﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace ServiceCore.Tool
{

    public interface ISnowflake_Helper
    {
        string IGet_SnowFlake_Id { get; }
        long IGet_SnowFlake_IdLong { get; }

    }
    public class Snowflake_Helper: ISnowflake_Helper
    {
        private readonly IConfiguration _configuration;
        private static Snowflake.Core.IdWorker work;//= new Snowflake.Core.IdWorker(workerId, 1);
        public Snowflake_Helper(IConfiguration configuration)
        {
            _configuration = configuration;
            work = new Snowflake.Core.IdWorker(workerId, 1);
        }
        public long workerId
        {
            get
            {
                long defworkid = 1;
                if (long.TryParse(_configuration["Snowflake:workerId"].ToString(), out defworkid))
                {
                    return defworkid;
                }
                else {
                    return 1;
                }
            }
        }
        /// <summary>
        ///  返回一个雪花算法数据ID
        /// </summary>
        public static string Get_SnowFlake_Id
        {
            get
            {
                long Nid = work.NextId();
                return Nid.ToString();
            }
        } 
        /// <summary>
        ///  返回一个雪花算法数据ID
        /// </summary>
        public static long Get_SnowFlake_LongId
        {
            get
            {
                long Nid = work.NextId();
                return Nid;
            }
        }         /// <summary>
        ///  返回一个雪花算法数据ID
        /// </summary>
        public  string IGet_SnowFlake_Id
        {
            get
            {
                long Nid = work.NextId();
                return Nid.ToString();
            }
        }
        ///  返回一个雪花算法数据ID
        /// </summary>
        public long IGet_SnowFlake_IdLong
        {
            get
            {
                long Nid = work.NextId();
                return Nid;
            }
        }

    }
}
